package com.prs.crm.dao.oa.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.oa.ArchivesDao;
import com.prs.crm.domain.hr.Dept;
import com.prs.crm.domain.oa.Archives;

public class ArchivesDaoImpl extends BaseDaoImpl<Archives> implements ArchivesDao{

	@Override
	public List<Archives> getAllArchives() {
		Criteria criteria = this.getSession().createCriteria(Archives.class);
		return criteria.list();
	}

	@Override
	public Collection<Archives> getRootArchives() {
		return (Collection<Archives>)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(Archives.class);
			        	criteria.add(Restrictions.isNull("parent"));
			        	criteria.addOrder(Order.asc("id"));
			        	return criteria.list();
			        }
				}
		);
	}

}
